package com.iflytek.sbd.controller;

import com.iflytek.sbd.po.db.Computer;
import com.iflytek.sbd.service.db.RedisService;
import com.iflytek.sbd.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.commands.JedisCommands;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @program: sbd
 * @description: 测试redis的
 * @author: 陈亮
 * @create: 2022-02-27 23:07
 */
@Api("/调试redis")
@RestController
@RequestMapping("/redis")
public class RedisController {
    private static final Logger log = LoggerFactory.getLogger(RedisController.class);

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private RedisService redisService;

    @PostMapping("/use")
    public String use(String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value);
        return stringRedisTemplate.opsForValue().get(key);
    }

    @ApiOperation(value = "测试redis进行方法结果缓存1")
    @PostMapping("/test")
    public String get(String key) {
        return redisService.get(key);
    }

    @ApiOperation(value = "测试redis进行方法结果缓存2")
    @PostMapping("/test1")
    public Computer get1(String key) {
        Computer computer = new Computer();
        computer.setId(key);
        return redisService.get1(computer);
    }


    @ApiOperation(value = "测试redis分布式锁实现")
    @PostMapping("/test2")
    public void get2(String key) {

    }


}
